import { defineStore } from "pinia"
import { ref,computed } from "vue"
import axios from "axios"

export const useCounterStore = defineStore('counter',() =>{
    //定义数据
    const count = ref(0)
    //定义数据的修改方法
    const increment = () => {
        count.value++
    }

    //getter 定义
    const mulGetter = computed(() => count.value * 2)
    //定义异步 action
    const list = ref([])
    const getList = async () => {
        //使用一个通用接口测试：geek.itheima.net/v1_0/channels
        const res = await axios.get("http://geek.itheima.net/v1_0/channels")
        list.value = res.data.data.channels
    }

    //return 后供组件使用
    return {
        count,
        mulGetter,
        list,
        getList,
        increment
    }
})